<?php

/*
|--------------------------------------------------------------------------
| Web Routes
|--------------------------------------------------------------------------
|
| This file is where you may define all of the routes that are handled
| by your application. Just tell Laravel the URIs it should respond
| to using a Closure or controller method. Build something great!
|
*/
use App\Services\ActionService;

Auth::routes();
Route::get('/home', 'HomeController@index');
Route::get('/logout', 'Auth\LoginController@logout');

const RESOURCES = [
    'users' => 'User', 
    'customers' => 'Customer', 
    'projects' => 'Project', 
    'groups' => 'Group',
    'acceptRecords' => 'AcceptRecord',
    'roles' => 'Role',
    'actions' => 'Action',
    'tags' => 'Tag',
];
Route::group([
    'prefix' => 'v1',
    'middleware' => ['auth', 'json', 'links', 'login'],
], function() {
    foreach (RESOURCES as $k => $item) {
        $controller_name = 'Resources\\'.$item.'Controller';
        Route::resource(
            $k,
            $controller_name,
            ['except' => ['create', 'edit'],]//除去这2个方法
        );
    }
});

ActionService::registerRoutes();

// 获取二维码图片
Route::get('/qrcode/{wxClientId}', 'ApiController@qrcode')->middleware('guest');

Route::group([
    'prefix' => 'v1',
    'middleware' => ['auth', 'json', 'login'],
], function () {
    //获取用户名下项目
    Route::get('/users/{user_id}/projects', 'UserProjectController@index');
    Route::get('/companies/{company_id}/wxClients', 'CompanyWxClientController@index');
    Route::get('/projects/{project}/users', 'UserProjectController@usersOf');
    Route::get('/wxclients/{wxClient}/contacts/{customer}/messages', 'WxclientContactMsgController@index');
    Route::get('/wxclients/contacts', 'WxclientContactMsgController@wxclientContact');
    // 修改密码
    Route::post('/auth/password/modify', 'Auth\PasswordController@changePassword');
    // 获取指定客户的认领关系数据
    Route::get('/customers/{customer_id}/acceptRecords', 'Resources\CustomerController@acceptRecords');
});

//忘记密码
Route::group([
    'prefix' => 'v1',
    'middleware' => ['json'],
], function () {
    //发送验证码
    Route::post('/auth/password/verify', 'Auth\ForgetPasswordController@getVerify');
    //重置密码
    Route::post('/auth/password/forgot', 'Auth\ForgetPasswordController@forgotPassword');
});

Route::get('send', 'TestSendController@index');